package com.cnblsp2.android.study.androidresources.menu;

import com.cnblsp2.android.study.androidresources.R;

import android.app.Activity;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.TextView;
import android.widget.Toast;

public class MenuResActivity extends Activity {

	private TextView textView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_menures);
		textView = (TextView) this.findViewById(R.id.activity_menures_txt);
		registerForContextMenu(textView);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = new MenuInflater(this);
		// 状态R.menu.context对应的菜单，并添加到menu中
		inflater.inflate(R.menu.my_menu, menu);
		return super.onCreateOptionsMenu(menu);
	}

	@Override
	public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
		MenuInflater menuInflater = new MenuInflater(this);
		// 状态R.menu.context对应的菜单，并添加到menu中
		menuInflater.inflate(R.menu.context, menu);
		menu.setHeaderIcon(R.drawable.phone_android);
		menu.setHeaderTitle("请选择背景色");
	}

	/**
	 * 上下文菜单被单击时触发
	 */
	@Override
	public boolean onContextItemSelected(MenuItem item) {

		Toast.makeText(this, "5678", Toast.LENGTH_SHORT).show();
		return true;
	}

	/**
	 * 菜单项被单击后的架设方法
	 */
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {

		Toast.makeText(this, "1234", Toast.LENGTH_SHORT).show();

		return true;

	}

}
